/*
 * Instruction.h
 *
 *  Created on: 13-Feb-2013
 *      Author: abhijeet
 */

#ifndef INSTRUCTION_H_
#define INSTRUCTION_H_
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <Def.h>
#include <Math.h>
#include <unordered_map>
#include <sstream>

#include "Table.h"
#include "Def.h"

using namespace std;


extern int *Memory;
extern int *Register;
extern int PC;
extern int memoryLimit;
extern int InstLimit;


class Instruction {

	//Fields and their names
	char upcode[5];
	char upcodeName[10];
	char rs[6];
	char rsName[10];
	char rt[6];
	char rtName[10];
	char rd[6];
	char rdName[10];
	char sa[6];
	char saName[10];

	char displacement[33];

	char binaryCode[33];

	InstType type;
	Table symbolTable;

public:
	Instruction(char * binary);
	int isEqual(char *);
	char *getName();
	virtual ~Instruction();
	void Initialize();
	void PrintInstruction(int memLoc);
	void PrintInstruction2(int memLoc);
	void GetInstruction(int memLoc,int format,string &output);
	char* GetDisplacement();
	void Execute();

};
//This declaration should be here. Do not move
extern unordered_map<int, Instruction*> instructionMap;

#endif /* INSTRUCTION_H_ */
